<template>
  <view>
    <view class="search-box">
      <my-search @click="gotoSearch"></my-search>
    </view>
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
      <swiper-item v-for="(item,i) in swiperList" key="i" >
        <navigator class="swiper-item" :url="'/subpkg/good_detail/good_detail?goods_id='+item.goods_id">
          <img :src="item.image_src"  />
        </navigator>
      </swiper-item>
    </swiper>
    
   <!-- 标题title -->
    <view class="nav-list">
      <view v-for="(item,i) in navList" :key="i" class="nav-item" @click="navClickHandle(item)">
        <img class="nav-imgs" :src="item.image_src"/>
      </view>
    </view>
    
    <!-- 图片 -->
    <view class="floor-list">
      <view class="floor-item" v-for="(item,i) in floorList" :key="i">
        <img :src="item.floor_title.image_src"   class="floor-title"/>
        <view class="floor-imgs-box">
          <navigator class="left-imgs-box" :url="item.product_list[0].url">
            <img :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width+'rpx'}" mode="widthFix"/>
          </navigator>
          
          <view class="right-imgs-box">
            <navigator class="right-imgs-item" v-for="(item2,i2) in item.product_list.slice(1)" :key="i2" :url="item2.url">
              <img :src="item2.image_src" :style="{width:item2.image_width+'rpx'}" mode="widthFix" />
            </navigator>
          </view>
        </view>
      </view>
    </view>
    
    
  </view>
</template>

<script>
  import badgeMix from '@/mixins/tabbar-badge.js'
  export default {
    mixins:[badgeMix],
    data() {
      return {
        swiperList:[],
        navList:[],
        floorList:[]
      };
    },
    onLoad() {
      this.getSwiperList(),
      this.getNavList(),
      this.getFloorList()
    },
    methods:{
      async getSwiperList(){
       const {data:res}=await uni.$http.get('/api/public/v1/home/swiperdata')
       if(res.meta.status!==200){
       return uni.$showMsg();
       }
       this.swiperList=res.message
       uni.$showMsg('请求成功了')
      },
      
      async getNavList(){
        const {data:res}=await uni.$http.get('/api/public/v1/home/catitems')
        if(res.meta.status!==200){
        return uni.$showMsg();
        }
        this.navList=res.message
        uni.$showMsg('请求成功了')
      },
      
      navClickHandle(item){
        if(item.name=='分类'){
          uni.switchTab({
            url:'/pages/cate/cate'
          })
        }
      },
      
     async getFloorList(){
       const {data:res}=await uni.$http.get('/api/public/v1/home/floordata')
       if(res.meta.status!==200){
         return uni.$showMsg();
         }
          res.message.forEach(floor=>{
            floor.product_list.forEach(prod=>{
              prod.url='/subpkg/goods_list/goods_list?'+prod.navigator_url.split('?')[1]
            })
          })
         this.floorList=res.message
         uni.$showMsg('请求成功了')
       },
       
       gotoSearch(){
         uni.navigateTo({
           url:'/subpkg/search/search'
         })
       }
      }
    }
  
</script>

<style lang="scss">
  .search-box {
    top: 0;
    position: sticky;
    z-index: 999;
  }
  
swiper{
  height: 330rpx;
  .swiper-item,img{
    width: 100%;
    height: 100%;
  }
}

.nav-list{
  display: flex;
  justify-content: space-around;
  margin: 15rpx;
}
.nav-imgs{
  width: 128rpx;
  height: 140rpx;
}
.floor-title{
  width: 100%;
  height: 60rpx;
}
.right-imgs-box{
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
}
.floor-imgs-box{
  display: flex;
  padding-left: 10rpx;
  
}


</style>
